 

function specialCheckCtrl($scope,$http, ngDialog, paFetchService, ngDialogConfirm) {
  'ngInject';

  // 获取实施单位
  this.units = [];
  paFetchService.getSectionList().then((resp) => {
    this.units = resp.data.data;
  });

  // 获取专项检查列表
  this.specialCheckList = [];
  // 查询安排任务信息
  this.queryData = {};
  this.paginationData = {
    pageNum: 1,
    pageSize: 10,
    total: '',
  };

  this.getCheckStatus = (status) => {
    switch(status) {
      case 0:
        return '未开始';
        break;
      case 1:
        return '进行中';
        break;
      case 2:
        return '待整改';
        break;
      case 3:
        return '已完成';
        break;
    }
  }

  // 删除专项任务
  this.deleteCheckItem = (item) => {
    ngDialogConfirm.confirm('删除专项任务', '确认删除此专项任务吗?')
      .then(() => {
        $http.delete(`${SERVER_CONTEXT}/api/securityActivities/specialCheck/deleteSpecialCheckById/${item.taskId}`)
          .then((resp) => {
            if (resp.data.success) {
              layer.msg(resp.data.message);
              this.initViewData();
            } else {
              layer.alert(resp.data.message);
            }
          });
      });
  }

  //更换页码时
  $scope.pageChange = () => {
    this.initViewData();
  };
  // 查询
  this.initViewData = () => {
    $http.post(`${SERVER_CONTEXT}/api/securityActivities/specialCheck/querySpecialCheckByCondition`,
      angular.extend(this.queryData, this.paginationData)
    ).
      then((resp) => {
        this.specialCheckList = resp.data.data;
        this.paginationData.total = resp.data.total;
      });
  };
  this.initViewData();
  // 根据时间条件查询
  this.search = (param) =>{
    if (param.startDateFrom.$valid && param.startDateTo.$valid) {
      if (param.startDateFrom.$viewValue < param.startDateTo.$viewValue) {
        this.initViewData();
      } else {
        layer.alert('起始时间取值范围不合理');
        return false;
      }      
    }

    if (param.endDateFrom.$valid && param.endDateTo.$valid) {
      if (param.endDateFrom.$viewValue < param.endDateTo.$viewValue) {
        this.initViewData();
      } else {
        layer.alert('结束时间取值范围不合理');
        return false;
      }
    } else {
      this.initViewData();
    }
    
    this.initViewData();
  };
  // 重置
  this.rest = () => {
    this.queryData = {};
  }

  // 升序、降序
  this.up = (param,index) => {   
    this.queryData.columeName = param;
    this.queryData.order = index;
    this.initViewData();
  }


}

export default specialCheckCtrl;